import Mock from 'mockjs'

// driverId = 224
const getShipDeteailById = '2'
const List = []
const count = 22

const transfer_storage = ['郑州中转库', '上海中转库', '南昌中转库', '成都中转库']
const car_brand = ['大众辉昂', '大众CROSSPOLO', '大众CRO2222', '大众奔腾']

// getWaybillList()
for (let i = 0; i < count; i++) {
  List.push(Mock.mock({
    id: getShipDeteailById,
    code: 'SP-mock' + '@increment',
    shipTaskCountBos: [
      { destLocationCode: '4',
        'endAddress|1': transfer_storage,
        gmtCreate: '@datetime("2018-MM-dd HH:mm:ss")',
        gmtDeliver: '@datetime("2018-MM-dd HH:mm:ss")',
        gmtSetoff: '@datetime("2018-MM-dd HH:mm:ss")',
        id: getShipDeteailById,
        itemCount: 6,
        originLocationCode: '3',
        'startAddress|1': transfer_storage,
        taskCode: 'ST-mock' + '@increment'
      }
    ]
  }))
}

// getWaybillListDetail()
const shipOrderItemBos_list = []
for (let i = 0; i < 6; i++) {
  shipOrderItemBos_list.push(Mock.mock({
    'id': '@increment',
    'shipOrderCode': null,
    'orderItemId': '@increment',
    'amount': null,
    'issueItemId': 'LSVCB73E1J2022695',
    'material|1': car_brand,
    'uom': null
  }))
}
const shipOrderItemCountBos_list = []
for (let i = 0; i < 3; i++) {
  shipOrderItemBos_list.push(Mock.mock({
    'issueItemId|1': car_brand,
    'amount|1-10': '2'
  }))
}
const shipTaskBos_list = []
for (let i = 0; i < 4; i++) {
  shipTaskBos_list.push(Mock.mock({
    'id': getShipDeteailById,
    'taskCode': 'ST-mock' + '@increment',
    'shipOrderCode': 'SO' + '@increment',
    'gmtStart': '@datetime("2018-MM-dd HH:mm:ss")',
    'gmtFinish': '@datetime("2018-MM-dd HH:mm:ss")',
    'gmtExpectStart': '@datetime("2018-MM-dd HH:mm:ss")',
    'gmtExpectFinish': '@datetime("2018-MM-dd HH:mm:ss")',
    'startAddress|1': transfer_storage,
    'endAddress|1': transfer_storage,
    'originLocationCode': '3',
    'destLocationCode': '4',
    'shipOrderItemBos': shipOrderItemBos_list,
    'shipOrderItemCountBos': shipOrderItemCountBos_list
  }))
}
export default {
  getWaybillList: config => {
    // console.log('mock-shipOrderApi-getWaybillList()-config', config)
    const { current, size, condition } = JSON.parse(config.body)
    const mockList = List.filter(item => {
      if (condition !== undefined) {
        if (item.id !== getShipDeteailById) return false
      }
      return true
    })
    const pageList = mockList.filter((item, index) => index < size * current && index >= size * (current - 1))
    // console.log('mock-shipOrderApi-geList()-pageList', pageList)
    const resData = {
      'code': 0,
      'data': {
        'total': mockList.length,
        'size': size,
        'pages': 0,
        'current': current,
        'records': pageList,
        'condition': {
          'driverId': condition.driverId
        },
        'asc': true,
        orderByField: 'gmt_create',
        'offsetCurrent': 0
      },
      'message': 'success'
    }
    console.log('mock-shipOrderApi-geList()-resData', resData)
    return resData
  },
  getWaybillListDetail: config => {
    // console.log('mock-shipOrderApi-getWaybillList()-config', config)
    // const { } = JSON.parse(config.body)
    const resData = {
      'code': 0,
      'message': 'success',
      'data': {
        'id': getShipDeteailById,
        'code': 'SP-mock' + '@increment',
        'shipTaskBos': shipTaskBos_list
      }
    }
    console.log('mock-shipOrderApi-getWaybillListDetail()-resData', resData)
    return resData
  }
}
